<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css/main.css" type="text/css" />
<link href="./css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="./css/themes/mac_os_x.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="./js/prototype.js"></script>
<script type="text/javascript" src="./js/scriptaculous.js"></script>
<script type="text/javascript" src="./js/controls.js"></script>
<script type="text/javascript" src="./js/window.js"></script>
<script type="text/javascript" src="./js/window_effects.js"></script>
<script type="text/javascript" src="./js/page.js"></script>
<script type="text/javascript">
	function showBox(){
		//alert("ok");
		if(!check_msie()){
			if(!confirm("Questo sito e' ottimizzato per i seguenti browser:" + '\n' + " - Firefox e derivati" + '\n' + " - Chrome e derivati" + '\n' + "Al momento stai usando Internet Explorer: il funzionamento del sito NON e' garantito con questo browser. Vuoi continuare?" )){
				return false;
			}
		}
	    $('overlay').show();
	    center('box');
	    $('nick').focus();
	    return false;
	}

	function hideBox(){
		//alert(t);
	    $('box').hide();
	    $('overlay').hide();
	    return false;
	}

	function center(element){
		//alert(element);
	    try{
	        element = $(element);
	    }catch(e){
	        return;
	    }

	    var my_width  = 0;
	    var my_height = 0;

	    if ( typeof( window.innerWidth ) == 'number' ){
	        my_width  = window.innerWidth;
	        my_height = window.innerHeight;
	    }else if ( document.documentElement &&
	             ( document.documentElement.clientWidth ||
	               document.documentElement.clientHeight ) ){
	        my_width  = document.documentElement.clientWidth;
	        my_height = document.documentElement.clientHeight;
	    }
	    else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
	        my_width  = document.body.clientWidth;
	        my_height = document.body.clientHeight;
	    }

	    element.style.position = 'absolute';
	    element.style.zIndex   = 99;

	    var scrollY = 0;

	    if ( document.documentElement && document.documentElement.scrollTop ){
	        scrollY = document.documentElement.scrollTop;
	    }else if ( document.body && document.body.scrollTop ){
	        scrollY = document.body.scrollTop;
	    }else if ( window.pageYOffset ){
	        scrollY = window.pageYOffset;
	    }else if ( window.scrollY ){
	        scrollY = window.scrollY;
	    }

	    var elementDimensions = Element.getDimensions(element);

	    var setX = ( my_width  - elementDimensions.width  ) / 2;
	    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

	    setX = ( setX < 0 ) ? 0 : setX;
	    setY = ( setY < 0 ) ? 0 : setY;

	    element.style.left = setX + "px";
	    element.style.top  = setY + "px";

	    element.style.display  = 'block';
	}

	function check_msie(){
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
			return false;
		}
		return true;
	}

	/*
	 * funzione di login 
	 */
	function do_login(type){
		var nick = $('nick').value;
		var pwd = $('pass').value;
		//alert(pwd);
		var pass = hex_md5(pwd);
		// local copy
		//var url = "http://registro.inrich.it/do_login.php";
		// seeweb
		var url = "do_login.php";
		var req = new Ajax.Request(url,
				  {
				    	method:'post',
				    	parameters: {nick: nick, pass: pass},
				    	onSuccess: function(transport){
				      		var response = transport.responseText || "no response text";
				      		alert(response);
				      		var dati = response.split(";");
				      		if(dati[0] == "ko"){
								alert("Errore SQL. \nQuery: "+dati[1]+"\nErrore: "+dati[2]);
								hideBox();
								return;
				      		}
				      		hideBox();
				      		$('links').innerHTML = "";
							//alert(response);
			            	gruppi = dati[1].split(",");
			            	for(i = 0; i < gruppi.length; i++){
			            		if(gruppi[i] == 1)
			            			$('links').innerHTML += "<a style='color: white' href='admin/index.php'>Amministrazione</a> | ";
			            		if(gruppi[i] == 2)
			            			$('links').innerHTML += "<a style='color: white' href='intranet/teachers/index.php'>Accedi come docente</a> | ";
			            		if(gruppi[i] == 3)
			            			$('links').innerHTML += "<a style='color: white' href='intranet/ata/index.php'>Accedi come ATA</a> | ";
			            		if(gruppi[i] == 4)
			            			$('links').innerHTML += "<a style='color: white' href='intranet/genitori/index.php'>Accedi come genitore</a> | ";
			            		if(gruppi[i] == 6)
			            			$('links').innerHTML += "<a style='color: white' href='intranet/office/index.php'>Accedi alle funzioni di segreteria</a> | ";
			            		if(gruppi[i] == 7)
			            			$('links').innerHTML += "<a style='color: white' href='intranet/manager/index.php'>Accedi come DS</a> | ";
			            	}
			            	$('links').innerHTML += "<a style='color: white' href='<?php print $_SESSION['__config__']['html_root'] ?>shared/do_logout.php'>Logout</a>";
				    	},
				    	onFailure: function(){ alert("Si e' verificato un errore..."); }
				  });
	}
	</script>
	<title>Registro elettronico</title>
</head>
<body>
	<div id="header">
		<div class="wrap">
			<?php include "header.php" ?>
			<?php include "shared/main_menu.php" ?>
		</div>
	</div>
	<div class="wrap">
		<div id="main" style="background-color: #FFFFFF; padding-bottom: 30px">
			<h3 style="margin-bottom: 20px; margin-left: auto; margin-right: auto; text-align: center">Accesso effettuato in modo corretto</h3>
			<table style="width: 90%; border-collapse: collapse; margin: auto">
				<tr><td colspan="2" style="border: 1px solid gray; text-align: center; font-weight: bold"><?php print $_SESSION['__current_year__']->to_string() ?></td></tr>
				<tr>
					<td style="20%; border: 1px solid gray; padding-left: 10px; font-weight: bold">Variabile</td>
					<td style="80%; border: 1px solid gray; padding-left: 10px; font-weight: bold">Valore</td>
				</tr>
					<?php
						while(list($k, $v) = each($_SESSION['__config__'])){
					?>
				<tr style="height: 30px">
					<td style="width: 20%; border: 1px solid gray; padding-left: 10px" id=""><?php print $k ?></td>
					<td style="width: 80%; border: 1px solid gray; padding-left: 10px;">
					<p id="<?php print $k ?>" style="margin-top: auto; margin-bottom: auto"><?php print $v ?></p>
					<script type="text/javascript"> 
					new Ajax.InPlaceEditor('<?php print $k ?>', './env_manager.php', { 
						callback: function(form, value) { return 'f=<?php print $k ?>&val='+encodeURIComponent(value); }
					});
					</script>
					</td >	
				</tr>
				<?php } ?>
			</table>
		</div>		
		<div id="footer">
			<p>Design: Luka Cvrk - <a href="http://www.solucija.com" title="Free Web Templates">Solucija</a></p>
		</div>		
		<form method="post" action="#">
   		<div id="overlay" onclick="hideBox()" style="display:none"></div>
		<div id="box" style="display:none">
	    <p><span id='login_error_msg' class="login_error" style="display:none">Dati di accesso non corretti</span></p>
	    <div style="clear:both"></div>
	    <p><span class="login_label">login</span> <span class="login_input"><input id="nick" type="text" name="nick" /></span></p>
	    <div style="clear:both"></div>
	    <p><span class="login_label">password</span> <span class="login_input"><input id="pass" type="password" name="pass" /></span></p>
	    <div style="clear:both"></div>
	    <br/><br/>    
	    <p style="width: 250px; float: right; margin-right: 15px; text-align: right">
	        <input type="button" onclick="do_login()" value="Login" style="border: 1px solid; width: 75px; font-size: 12px"/>&nbsp;&nbsp;&nbsp;&nbsp;
	        <input type="button" onclick="hideBox()" value="Chiudi" style="border: 1px solid; width: 75px; font-size: 12px"/>
	    </p>
	    <br/><br/>
	    <div style="clear:both"></div>
		</div>
		</form>	
	</div>	
</body>
</html>